/**
 * Copyright (c) 2016 Lenovo Group
 * All Rights Reserved.
 * 
 * Project Name:app-gateway
 * Create Time: 2016年1月18日 下午4:14:53
 */
package com.lenovo.lmrp.server.appgateway;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.lenovo.sdc.framework.rest.RestServer;
import com.lenovo.sdc.framework.util.AttributeBean;

/**
 * @author zhangzhenga
 *
 */
public class AppGatewayService {
 
    private static final Logger log = LoggerFactory.getLogger(AppGatewayService.class);

    private RestServer server;
    private static final String HOST = "appgateway.host";
    private static final String PORT = "appgateway.port";
    private static final String SSL = "appgateway.ssl";
    private static final String CONTEXT = "appgateway.context";
    private static final String SCAN_PATH = "appgateway.scanpath";
    private AttributeBean attributes;

    /**
     * 
     */
    public AppGatewayService(AttributeBean attributes) {
        this.attributes = attributes;
    }

    public void start() {
        server = new RestServer(attributes.getAttribute(HOST, "0.0.0.0"), attributes.getAttribute(PORT, 7001),
            attributes.getAttribute(SSL, false));
        server.start();
        server.deploy(attributes.getAttribute(CONTEXT, ""),
            new String[] { attributes.getAttribute(SCAN_PATH, "com.lenovo.lmrp.server.appgateway.spi") });
        log.debug("App Gateway service has deployed!");
    }

    public void stop() {
        server.stop();
        log.debug("appgateway server has stoped!");
    }
}
